package com.charonmc.parkour;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public class PakourItemListener implements Listener {
    @EventHandler
    public void onUse(PlayerInteractEvent event){
        if (event.getItem() != null && event.getItem().getItemMeta().getDisplayName() != null){
            if (event.getItem().getItemMeta().getDisplayName().equals("§e§l返回记录点")){
                event.getPlayer().chat("/BackCheckpoint");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§e§l返回起点")){
                event.getPlayer().chat("/BackStart");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§c§l退出")){
                event.getPlayer().chat("/End");
            }
        }
    }

    @EventHandler
    public void onPlayerBlockItem(BlockPlaceEvent event){
        if (event.getItemInHand() != null && event.getItemInHand().getItemMeta().getDisplayName() != null){
            if (event.getItemInHand().getItemMeta().getDisplayName().equals("§e§l返回记录点")){
                event.getPlayer().chat("/BackCheckpoint");
            } else if (event.getItemInHand().getItemMeta().getDisplayName().equals("§e§l返回起点")){
                event.getPlayer().chat("/BackStart");
            } else if (event.getItemInHand().getItemMeta().getDisplayName().equals("§c§l退出")){
                event.getPlayer().chat("/End");
            }
        }
        event.setCancelled(true);
    }
}
